-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post excerpt > Ensure the postId from the block context is used to get_the_excerpt #49495
Post excerpt > Ensure the postId from the block context is used to get_the_excerpt #49495
Conversation
…f relying on the global post object.
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @nefeline! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
Thank you for opening the bug fix. It makes sense and aligns with how it works in
Thank you for linking to that prior work from @spacedmonkey. Would it also he beneficial for performance to use the post object here? |
There is a related discussion here but not enough testing has been done: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving the changes.
The follow-up could cover potential perf improvements. We could also refactor the code so it's easier to follow:
$excerpt = get_the_excerpt( $block->context['postId'] );
if ( isset( $excerpt_length ) ) {
$excerpt = wp_trim_words( $excerpt, $excerpt_length );
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
I agree that it would be better if we tweak the code a bit like @gziolo suggested above, but no strong feelings either way.
Congratulations on your first merged pull request, @nefeline! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
What?
Ensures the
postId
from the block context is used for fetching the post excerpt.Why?
Similar to this change made to the Post Title block, here we can ensure that independent of where the Post Excerpt block is added, the rendered content will be aligned with the context of the block itself rather than the global post.
For context, this limitation surfaced while working on the new Single Product Block on WooCommerce blocks, where the displayed excerpt would match the current post rather than the block context while at the same time, the Post Title block would respect the block context accordingly.
Testing Instructions